package com.seven.micro_service.Config;



import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;


@Configuration
public class JDBCConfig {
    @Value("${spring.datasource.url}")
    String jdbcUrl;
    @Value("${spring.datasource.driver-class-name}")
    String igniteDriver;

    @Bean
    DataSource createDataSource() {
        HikariConfig config = new HikariConfig();
        config.setDriverClassName(igniteDriver);
        config.setJdbcUrl(jdbcUrl);

        config.addDataSourceProperty("autoCommit", "true");
        config.addDataSourceProperty("connectionTimeout", "5");
        config.addDataSourceProperty("idleTimeout", "60");
        return new HikariDataSource(config);
    }

    @Bean
    JdbcTemplate createJdbcTemplate(@Autowired DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
}
